#include "main.h"

#include "board.h"
#include "my_lib/cmd_analyse.h"
#include "my_lib/led.h"
#include "my_lib/my_log.h"
#include "my_task.h"
#include "menu.h"


int32_t main(void)
{
    taskENTER_CRITICAL();  //初始化完成前禁止调度
    BoardInit();

    BaseType_t re;

    taskENTER_CRITICAL();

    //测试任务
    re = xTaskCreate(TestTask, "test task", 256, NULL, 1, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "test task create failed");
    }
    //闪灯任务
    re = xTaskCreate(LedTask, "led task", 64, NULL, 1, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "led task create failed");
    }
    //按键任务
    re = xTaskCreate(ButtonTask, "button task", 64, NULL, 5, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "button task create failed");
    }
    //命令任务
    re = xTaskCreate(CmdTask, "cmd task", 256, NULL, 6, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "cmd task create failed");
    }
    //菜单任务(主要逻辑)
    re = xTaskCreate(MenuTask, "menu task", 256, NULL, 6, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "menu task create failed");
    }
    //蜂鸣器任务
    re = xTaskCreate(BeepTask, "beep task", 64, NULL, 1, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "beep task create failed");
    }
    //舵机任务
    re = xTaskCreate(SteerTask, "steer task", 128, NULL, 4, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "steer task create failed");
    }
    //追点扫线任务
    re = xTaskCreate(PointFollowTask, "follow task", 128, NULL, 5, NULL);
    if(re != pdPASS){
        MY_LOGE("rtos", "follow task create failed");
    }
    //k210通信
    CommunicationInit();

    SetBeepFun(0, BeepOnMement, 100);

    vTaskDelete(NULL);
    taskEXIT_CRITICAL();

    taskEXIT_CRITICAL();
    /* 启动调度器 */
    vTaskStartScheduler();
}



/******************************************************************************
 * EOF (not truncated)
 ******************************************************************************/
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
    /* USER CODE BEGIN 6 */
    /* User can add his own implementation to report the file name and line number,
       tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    /* USER CODE END 6 */

    printf("Wrong parameters value: file %s on line %d\r\n", file, line);
}
#endif /* USE_FULL_ASSERT */

